package com.unis.datapush.service.impl.zhlg;

import com.unis.datapush.mapper.zhlg.ZhHotelDataMapper;
import com.unis.datapush.service.zhlg.ZhHotelDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class ZhHotelDataServiceImpl implements ZhHotelDataService {

    @Autowired
    private ZhHotelDataMapper zhHotelDataMapper;


    @Override
    public List<Map<String, Object>> getZtryMsg(String startTime) throws Exception {

       // List<Map<String, Object>> result = zhHotelDataMapper.getZtryMsg(sfzh);
        List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
        //获取查询范围内的旅馆入住信息
        List<Map<String, Object>> hotelList =  zhHotelDataMapper.getHotlCheckInMsg(startTime);
        for (Map<String, Object> m:hotelList) {
            String sfzh = String.valueOf(m.get("LK_ZJHM"));
            //通过身份证号校验是否是在逃人员
            int count = zhHotelDataMapper.checkZtry(sfzh);
            if(count > 0){
                String earlyMsg = "【在逃人员预警】"+m.get("LGDM")+"发现有在逃人员，请进行关注。";
                m.put("earlyMsg",earlyMsg);
                result.add(m);
            }
        }
        return result;
    }

    @Override
    public List<Map<String, Object>> getManLkZdplMsg() throws Exception {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        String month_start_tim = sf.format(new Date());//月初时间
        Calendar d = Calendar.getInstance();
        d.add(Calendar.DATE,30);
        String month_end_tim = sf.format(d.getTime());
        List<Map<String, Object>> res = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> lk = zhHotelDataMapper.getLkZdplMsg(month_start_tim,month_end_tim);
        if(lk != null && lk.size()>0){
            for (Map<String, Object> re:lk) {
                //提醒信息
                String msg = "【频繁入住异常】"+re.get("LGDM")+"发现有频繁入住异常人员，请进行关注。";
                re.put("yjMsg",msg);
                res.add(re);
            }
        }

        return res;
    }

    @Override
    public List<Map<String, Object>> getWomanLkZdplMsg() throws Exception {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
        String month_start_timv = sf.format(new Date());//月初时间
        Calendar d = Calendar.getInstance();
        d.add(Calendar.DATE,30);
        String month_end_timv = sf.format(d.getTime());
        List<Map<String, Object>> resl = new ArrayList<Map<String, Object>>();
        List<Map<String, Object>> wlk = zhHotelDataMapper.getLkZdplMsgWoman(month_start_timv,month_end_timv);
        if(wlk != null && wlk.size()>0){
            for (Map<String, Object> ress:wlk) {
                //提醒信息
                String wmsg = "【频繁入住异常】"+ress.get("LGDM")+"发现有频繁入住异常人员，请进行关注。";
                ress.put("yjWMsg",wmsg);
                resl.add(ress);
            }
        }
        return resl;
    }
}
